home *** CD-ROM | disk | FTP | other *** search
- /* VMGO/CCC
- * virtual memory current-line control functions
- *
- * Copyright 1983, 1984 by Jim Kyle - All Rights Reserved
- * Licensed for individual non-commercial use only.
- *
- * created: November 24, 1983 - Jim Kyle
- * changed: February 11, 1984 - Jim Kyle
- * last changed: March 3-9, 1984 - Jim Kyle
- *
- *
- NOTE:
- These routines are the only ones in the entire VM
- system which are permitted to change the values of
- the current-line counter Cur_ln and the data index
- Dbndx. Other routines can and do change Flcb, Llcb,
- and Lltf, especially when lines are moved from one
- block to another, inserted, or deleted, but only
- the VMGO module modifies the current line position.
- */
-
- /*
- * go_to() makes 'tgt' the current line
- * changed 2/29/84 to improve goto response time--jk
- * changed 3/7/84 to prevent going outside file--jk
- */
- go_to(tgt) int tgt;
- { tgt = max(0, min(tgt,Lltf)); /* map into true range */
- if (tgt <= (Cur_ln >>1)) /* closer to front... */
- go_top(); /* sets Cur_ln to 0 or 1 */
- else if ((tgt-Cur_ln)>(Lltf-tgt)) /* closer to end... */
- go_eof(); /* sets Cur_ln to Lltf */
- return(tgt > Cur_ln ? go_f(tgt) : go_p(tgt));
- }
-
- /*
- * go_nxl() makes next line the current one
- */
- go_nxl()
- { return(go_f(Cur_ln + 1)); }
-
- /*
- * go_pvl() makes prev line the current one
- */
- go_pvl()
- { return(go_p(Cur_ln - 1)); }
-
- /*
- * go_f() moves toward EOF until 'tgt' is found
- */
- go_f(tgt) unsigned int tgt; /* changed 3/7/84 - jk */
- { tgt = min(tgt, Lltf); /* stay inside the file */
- while (tgt > Llcb) {
- if (*Nxptr)
- vm_abt(go_nxb(), "go_f");
- else
- tgt = Llcb; /* catch empty file condition */
- }
- while (tgt > Cur_ln++)
- Dbndx += getwd(clad());
- --Cur_ln; /* take out the overshoot!! */
- return(OK);
- }
-
- /*
- * go_p() moves toward HOF until 'tgt' is found
- */
- go_p(tgt) int tgt;
- { if (tgt < 2) return(go_top());
- while (tgt < Flcb) {
- if (Curr) /* 3-7-84 */
- vm_abt(go_pvb(), "go_p");
- else
- tgt = Flcb; /* 3-3-84 -- stop at top!!! */
- }
- Cur_ln = Flcb;
- Dbndx = 0;
- return(go_f(tgt));
- }
-
- /*
- * go_top() goes to front of file without search
- */
- go_top()
- { vm_abt(vm_get(0), "go_top");
- Dbndx = 0;
- Cur_ln = Flcb = 1;
- Llcb = *Lcptr;
- return(Llcb ? OK : go_nxb()); /* 3-3-84 */
- }
-
- /*
- * go_eob() goes to the last line of the current
- * block.
- */
- go_eob()
- { unsigned int tmp;
- tmp = Flcb; /* start at top */
- Dbndx = 0;
- while (tmp++ < Llcb) /* step thru block */
- Dbndx += getwd(clad());
- if ((Cur_ln = Llcb) < Flcb) go_pvb(); /* empty! */
- }
-
- /*
- * go_eof() goes to end of file without search
- */
- go_eof()
- { vm_abt(vm_get(0), "go_eof 1");
- vm_abt(vm_get(*Pvptr), "go_eof 2");
- Flcb = (Llcb =Lltf) + 1 - *Lcptr; /* 3-9-84 */
- return(go_eob()); /* 3-9-84 */
- }
-
- /*
- * go_pvb() moves to last line of prev block.
- * If on first block, returns OK.
- */
- go_pvb()
- { if (Curr) {
- Llcb -= *Lcptr; /* set for new block */
- vm_abt(vm_get(*Pvptr), "go_pvb");
- Flcb = Llcb - *Lcptr + 1;
- go_eob();
- }
- /* else at front: */
- return(OK); /* 3-9-84 */
- }
-
- /*
- * go_nxb() moves to first line of next block.
- * If on last block, returns OK.
- */
- go_nxb()
- { if (*Nxptr) {
- vm_abt(vm_get(*Nxptr), "go_nxb");
- Cur_ln = Flcb = Llcb + 1; /* Llcb is of OLD */
- Llcb += *Lcptr;
- Dbndx = 0;
- }
- /* else at end: */
- return(OK); /* 3-9-84 */
- }
-
-